package com.xuan.bigdog.lib.widgets.title;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xuan.bigapple.lib.utils.Validators;
import com.xuan.bigdog.R;
import com.xuan.bigdog.lib.widgets.BaseLayout;

/**
 * 公共标题栏
 * 
 * @author xuan
 */
public class DGTitleLayout extends BaseLayout {
	/** 返回布局 */
	private View returnLt;
	/** 返回按钮 */
	private ImageView returnIv;

	/** 右边文字 */
	private TextView rightTv;
	/** 中间标题 */
	private TextView titleTv;

	public DGTitleLayout(Context context) {
		super(context);
	}

	public DGTitleLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void dgInit() {
		inflate(getContext(), R.layout.dg_widgets_title_titlelayout, this);
		returnLt = findViewById(R.id.returnLt);
		returnIv = (ImageView) findViewById(R.id.returnIv);
		rightTv = (TextView) findViewById(R.id.rightTv);
		titleTv = (TextView) findViewById(R.id.titleTv);
	}

	/**
	 * 初始化标题栏
	 * 
	 * @param title
	 */
	public void initTitle(String title) {
		initTitle(title, null);
	}

	/**
	 * 初始化标题栏
	 * 
	 * @param title
	 * @param returnListener
	 */
	public void initTitle(String title, View.OnClickListener returnListener) {
		initTitle(title, returnListener, null, null);
	}

	/**
	 * 初始化标题栏
	 * 
	 * @param title
	 * @param returnListener
	 * @param rightText
	 * @param rightListener
	 */
	public void initTitle(String title, View.OnClickListener returnListener,
			String rightText, View.OnClickListener rightListener) {
		if (!Validators.isEmpty(title)) {
			titleTv.setText(title);
			titleTv.setVisibility(View.VISIBLE);
		} else {
			titleTv.setVisibility(View.GONE);
		}

		if (null != returnListener) {
			returnLt.setVisibility(View.VISIBLE);
			returnLt.setOnClickListener(returnListener);
		} else {
			returnLt.setVisibility(View.GONE);
		}

		if (!Validators.isEmpty(rightText)) {
			rightTv.setText(rightText);
			rightTv.setVisibility(View.VISIBLE);
			rightTv.setOnClickListener(rightListener);
		} else {
			rightTv.setVisibility(View.GONE);
		}
	}

	public View getReturnLt() {
		return returnLt;
	}

	public TextView getRightTv() {
		return rightTv;
	}

	public TextView getTitleTv() {
		return titleTv;
	}

}
